#ifndef Format_INCLUDED
#define Format_INCLUDED

#include <string>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>

using std::string;

// 暂时就不用传引用参数了，即不用考虑完美转发了,C_Style,%s needs .c_str()
inline string format(const char *fmt,...)
{
    const int len = 256;
    char buf[len] = {0};
    va_list start;
    va_start(start,fmt);
    int ret = vsnprintf(buf,len,fmt,start);
    if (ret >= len)
    {
        // 实际需要的长度
        int len2 = ret + 1;
        char* pbuf = new char[len2];
        memset(pbuf,0,len2);
        va_end(start);
        va_start(start,fmt);
        ret = vsnprintf(pbuf,len2,fmt,start);
        string tmp(pbuf);
        delete [] pbuf;
        return tmp;
    }
    va_end(start);
    
    return string(buf);
}

#endif



